package com.blog.module.news.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.common.mybatis.Page;
import com.blog.common.mybatis.ParsePagination;
import com.blog.module.news.mapper.NewsInfoMapper;
import com.blog.module.news.pojo.News;
import com.blog.module.news.pojo.NewsExample;
import com.blog.module.news.pojo.NewsExample.Criteria;
import com.blog.module.news.pojo.NewsInfo;
import com.blog.module.news.pojo.NewsInfoExample;
import com.blog.module.news.vo.NewsInfoVo;

/**
 * @Title: NewsInfoService.java
 * @Description: TODO
 * @author user
 * @date 2016年7月28日 下午3:46:48
 * @version V1.0
 */
@Service
public class NewsInfoService {

	@Autowired
	private NewsInfoMapper newsInfoMapper;

	public Page pageNewsInfoList(NewsInfo newsinfo) {
		ParsePagination pagination = new ParsePagination();
		int pageNo = pagination.getPageNo();
		int pageSize = pagination.getPageSize();
		int count = newsInfoMapper.countNewInfoBytitleAndnewsId(newsinfo);
		List<NewsInfoVo> list = new ArrayList<NewsInfoVo>();
		Page page = new Page(count, pageNo, pageSize, list);
		list = newsInfoMapper.selectNewInfoBytitleAndnewsId(newsinfo,
				(pageNo - 1) * pageSize, pageSize);
		page.setList(list);
		return page;

	}

	public int insert(NewsInfo newInfo) {
		return newsInfoMapper.insert(newInfo);
	}

	public int update(NewsInfo newInfo) {
		return newsInfoMapper.updateByPrimaryKeySelective(newInfo);
	}

	public int del(int id) {
		return newsInfoMapper.deleteByPrimaryKey(id);
	}

	public NewsInfoVo selectById(int id) {
		return newsInfoMapper.selectById(id);
	}

}
